package com.car.comm;

import java.util.HashMap;

/**
 *  错误码控制类
 * @author Xairy
 */
public class ErrorAgent{
	static HashMap<Integer, ErrorMsg> errorMap 
							= new HashMap<Integer, ErrorMsg>();
	static final String CommUserError = "对不起,系统繁忙";
	static final String NetworkUserError = "网络连接失败";
	static final String DownloadFailedError = "对不起，下载失败";
	
	private static void ERROR(int code, 
							  String innerErrorMsg,
							  String userErrorMsg){
		errorMap.put(code, new ErrorMsg(innerErrorMsg, userErrorMsg));
	}
	
	public static String GetInnerErrorMsg(int errorCode){
		ErrorMsg msg = errorMap.get(errorCode);
		if(msg != null){
			return msg.getInnerErrorMsg();
		}
		return "未知的系统错误";
	}
	
	public static String GetUserErrorMsg(int errorCode){
		ErrorMsg msg = errorMap.get(errorCode);
		if(msg != null){
			return msg.getUserErrorMsg();
		}
		return CommUserError;
	}
	
	public static final int EHttpClientProtocolError = 1;
	public static final int EHttpIoError = 2;
	public static final int EHttpStatusNotOK = 3;
	public static final int EDataMappingFailed = 4;
	public static final int EDownloadFailed = 5;
	static{
		ERROR(0, "Success", "");
		ERROR(EHttpClientProtocolError, "Http Client Protocol Error", NetworkUserError);
		ERROR(EHttpIoError, "Http IO Error", NetworkUserError);
		ERROR(EHttpStatusNotOK, "Http Status Not OK", CommUserError);
		ERROR(EDataMappingFailed, "DataMapping Failed", CommUserError);
		ERROR(EDownloadFailed, "Download Failed", DownloadFailedError);
	}
}
